#coding=utf-8?
import re
from .coursegradrequire import CourseGradRequire


# 该类对某张特定的表的各项数据进行操作
class Course():
    def __init__(self, cs):
        self.courses = cs

        self.semester =0
        self.period_prac = 0  # 实践学时
        self.period_prac_in = 0   # 实践学时——课内
        self.period_prac_out = 0  # 实践学时-课外+线上
        self.groupMask = 1
        self.name = ""

        self.dictData = {
            "课程序号": 0,
            "课程代码": "",
            "课程名称": "",
            "学时数": 0,
            "学分数": 0,
            "理论": 0,
            "课内实践": 0,
            "课外实践": 0,
            "线上": 0,
            "开课学期": 0,
            "周学时": 0,
            "考核方式": "",
            "备注": "",
            "实践周数": 0,
            "学期安排": 0,
            "分组统计": 0,
            "毕业要求": "",
            "人文社会科学类": 0,
            "自然科学类": 0,
            "工程实践与毕业设计": 0,
            "工程基础类与专业类": 0
        }

        self.gradReq = CourseGradRequire()

    def load(self, titleDict, data, index):
        for k,v in titleDict.items():
            if k in self.dictData:
                self.dictData[k] = data[v] or self.dictData[k]
        self.period_prac_in = int(self.get("课内实践"))
        self.period_prac_out = int(self.get("课外实践") + self.get("线上"));
        self.period_prac = self.period_prac_in + self.period_prac_out;
        self.semester = int(max(self.get("开课学期"), self.get("学期安排")))
        self.name = self.get("课程名称")


        if "分组统计" in titleDict:
            self.groupMask = 1 if self.dictData["分组统计"]  else None

        if "毕业要求" in titleDict:
            self.gradReq.load(self.dictData["毕业要求"])

    def get(self, title):
        if title in self.courses:
            return self.dictData[title]
        else:
            return 0

if __name__ == '__main__':
    pass